<?php

namespace App\Http\Requests\Admin;

use App\Models\WebConfig;
use Illuminate\Foundation\Http\FormRequest;

/**
 * Class 后台登录中间件
 * @package App\Http\Requests\Admin
 */
class LoginRequest extends FormRequest
{
    /**
     * 确定用户是否有权发出此请求。
     *
     * @return bool
     */
    public function authorize()
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
    	$captcha_config = WebConfig::find(11);
        return [
			'username'=>'bail|required|string|between:3,12',
			'password'=>'bail|required|string|between:3,16',
			'captcha'=> $captcha_config->value == 1 ? 'required|captcha' : '', //判断是否开启验证码
        ];
    }


	public function attributes()
    {
		return [
			'username'=>'管理员账号',
			'password'=>'管理员密码',
			'captcha'=>'验证码',
		];
    }


    public function messages()
	{
		return [
			'captcha.captcha'=>'验证码错误',
		];
	}


}
